//
//  MJ_PlatDetailTableViewCell.m
//  UEAssistant
//
//  Created by mac on 2018/2/9.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_PlatDetailTableViewCell.h"
#import "UIColor+Extend.h"

@interface MJ_PlatDetailTableViewCell ()<LWAsyncDisplayViewDelegate>

@property (strong, nonatomic)LWAsyncDisplayView *asyncDisplayView;

@end

@implementation MJ_PlatDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.asyncDisplayView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.asyncDisplayView.frame = CGRectMake(0, 0, Screen_Width, self.layout.cellHeight);
}

- (void)setLayout:(MJ_PlatDetailLayout *)layout {
    if (_layout != layout) {
        _layout = layout;
        self.asyncDisplayView.layout = layout;
    }
}


- (void)extraAsyncDisplayIncontext:(CGContextRef)context
                              size:(CGSize)size
                       isCancelled:(LWAsyncDisplayIsCanclledBlock)isCancelled {
    if (!isCancelled()) {
        //设置虚线颜色
        CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"#eeeeee"].CGColor);
        if (_index == 1 && _currentTaskType == MJTaskOrderTranslateExample) {
            //设置线宽度
            CGContextSetLineWidth(context, 60);
            //设置线绘制起点
            CGContextMoveToPoint(context, 0, self.frame.size.height-40);
            //设置线绘制终点
            CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height-40);
            
            CGContextDrawPath(context, kCGPathStroke);
            
        }else if(_index != 2){

            //设置线宽度
            CGContextSetLineWidth(context, 10);
            //设置线绘制起点
            CGContextMoveToPoint(context, 0, self.frame.size.height-5);
            //设置线绘制终点
            CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height-5);

            CGContextDrawPath(context, kCGPathStroke);
        }
        
    }
}

- (void)lwAsyncDisplayView:(LWAsyncDisplayView *)asyncDisplayView didCilickedImageStorage:(LWImageStorage *)imageStorage touch:(UITouch *)touch {
    if (imageStorage.tag == 4096) {
        if (self.clickPhoneIconCallback) {
            self.clickPhoneIconCallback(self);
        }
    }
}

- (void)lwAsyncDisplayView:(LWAsyncDisplayView *)asyncDisplayView didCilickedTextStorage:(LWTextStorage *)textStorage linkdata:(id)data {
    if ([data isEqualToString:@"checkAll"]) {
        if (self.clickedOpenCellCallback) {
            self.clickedOpenCellCallback(self);
        }
    }
}

- (LWAsyncDisplayView *)asyncDisplayView {
    if (!_asyncDisplayView) {
        _asyncDisplayView = [[LWAsyncDisplayView alloc] initWithFrame:CGRectZero];
        _asyncDisplayView.displaysAsynchronously = NO;
        _asyncDisplayView.delegate = self;
    }
    return _asyncDisplayView;
}

@end
